﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;
using System.Data;

namespace TranTekBE.KPI_NhanSu
{
    public partial class Chinh_Sua_Danh_Gia : PagePopUp
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load JS
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "LoadJS", "LoadJS();", true);
            if (!IsPostBack)
            {
                
                string get_id_user = FunctionsUtils.GetValueStringFromQueryString("iduser", "0");
                string sql_get_user_danh_gia = "SELECT * FROM tbl_UserKPI Where ID_USER = '" + get_id_user + "'";
                DataSet sql_popup_danh_gia_user = FunctionsUtils.Database2.ExecuteQuery(sql_get_user_danh_gia);
                if (sql_popup_danh_gia_user != null)
                {
                    //
                    lblUserName.Text = sql_popup_danh_gia_user.Tables[0].Rows[0]["NAME_USER"].ToString();
                    lblFullName.Text = sql_popup_danh_gia_user.Tables[0].Rows[0]["HO_USER"].ToString()
                        + "" + sql_popup_danh_gia_user.Tables[0].Rows[0]["TEN_USER"].ToString();                   
                }
                FunctionsUtils.BindDataForControlList_1_10(droplist_DongPhuc, "10", "10");
                FunctionsUtils.BindDataForControlList_1_10(droplist_GiaoTiep, "10", "10");
                FunctionsUtils.BindDataForControlList_1_10(droplist_Kiem_Ke, "10", "10");
                FunctionsUtils.BindDataForControlList_1_10(droplist_NangLuong, "10", "10");
                FunctionsUtils.BindDataForControlList_1_10(droplist_ThaiDo, "10", "10");
            }
        }
      
        protected void btnEdit_DanhGia_Click(object sender, EventArgs e)
        {
            string get_id_user_danh_gia = FunctionsUtils.GetValueStringFromQueryString("iduser", "0");
            if ( droplist_ThaiDo.SelectedValue.ToString() != "" && droplist_DongPhuc.SelectedValue.ToString() != "" && droplist_GiaoTiep.SelectedValue.ToString() != "" && droplist_NangLuong.SelectedValue.ToString() != "" && droplist_Kiem_Ke.SelectedValue.ToString() != "")
            {
                try
                {
                    // Add thông tin người dùng đánh giá
                    string sql_update_user_danh_gia = @"
                                    INSERT INTO tbl_DanhGiaUser
                                    (ID_USER,NAME_USER,DANH_GIA_CHUYEN_MON,DANH_GIA_THAI_DO,DANH_GIA_DONG_PHUC,DANH_GIA_GIAO_TIEP,DANH_GIA_NANG_LUONG,DANH_GIA_KIEM_KE,NGAY_TAO,NGUOI_TAO,BINH_LUAN)
                                    VALUES
                                    (       '" + get_id_user_danh_gia + @"',
                                            '" + lblUserName.Text + "',"
                                            + 0 + ","
                                            + Convert.ToInt32(droplist_ThaiDo.SelectedValue.ToString()) + ","
                                            + Convert.ToInt32(droplist_DongPhuc.SelectedValue.ToString()) + ","
                                            + Convert.ToInt32(droplist_GiaoTiep.SelectedValue.ToString()) + ","
                                            + Convert.ToInt32(droplist_NangLuong.SelectedValue.ToString()) + ","
                                            + Convert.ToInt32(droplist_Kiem_Ke.SelectedValue.ToString()) + ",'"
                                            + DateTime.Now + "','"
                                            + UserInfo.UserName
                                            + "',N'" + txtareaNhanXet.Text.ToString().Replace("'","''") + "')";

                    FunctionsUtils.Database2.ExecuteNonQuery(sql_update_user_danh_gia);
                    Page page = (HttpContext.Current.Handler as Page);
                    if (page != null)
                    {
                        //page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "key", "alert('Bạn đã đánh giá thành công!')", true);
                        Response.Write("<script>alert('Bạn đã đánh giá thành công!');</script>");
                        ClosePopup(false);
                    }
                    
                }
                catch (Exception ex)
                {
                    ltAddErr.Text = ex.Message;
                }
            }
            else
            {
                ltAddErr.Text = "Bạn chưa chấm đủ điểm! Vui lòng kiểm tra lại";
                ltAddErr.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}